import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { getGameList, getGameListByArray } from '@/api/game';

export const useGameInfoStore = defineStore('gameInfo', () => {
  const gameKinds = ref<any[]>([]);
  const gameTypeList = ref<any[]>([]);
  const gameBannerList = ref<any>({});

  function setGameKinds(list: any[]) {
    gameKinds.value = list;
  }

  function updateGameType(successCallback: () => void = ()=>{}) {
    getGameListByArray()
    .then((res: any) => {
      let list:any[] = [];
      if (Array.isArray(res)) {
        list = res
      }
      gameTypeList.value = list;
    })
    .catch((err: any) => {
      console.log(err);
    })
    successCallback();
  }

  function updateGameBanner() {
    getGameList()
    .then((gameListRes: any) => {
      gameBannerList.value = gameListRes
    })
    .catch((err: any) => {
      console.log(err)
    })
  }

  return { 
    gameKinds, 
    gameTypeList, 
    gameBannerList,
    setGameKinds, 
    updateGameType, 
    updateGameBanner 
  }
})
